-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SubMesh::RecalculateNormals improvement #609
Conversation
I force-pushed commit due to previous one was not signed and I made boundary check more strict |
looks like there is still an issue with DCO, can you try fix it again? |
I was testing this with a capsule shape and I noticed that a seam is now visible after the changes: The From the commit msg, the loop was actually implemented on purpose to make objects appear smoother. The effect of that loop is that more normals are updated instead of limiting to 3 normals. Not efficient but produces smoother results. I'm leaning towards keeping the current code as it was intentional. |
I see. Thank you for testing and clarification. The main problem with current code that it could work about a minute if polygon has quite a lot of triangles even on a modern hardware. Maybe I can try to re-implement initial behaviour with unordered_map. I guess it should be ok to exchange execution time to a memory consumption spike |
yes that would be good to try, thanks |
2626310
to
5e36661
Compare
Signed-off-by: Maksim Derbasov <[email protected]>
Signed-off-by: Maksim Derbasov <[email protected]>
Signed-off-by: Maksim Derbasov <[email protected]>
Signed-off-by: Maksim Derbasov <[email protected]>
Signed-off-by: Maksim Derbasov <[email protected]>
5e36661
to
e22e6ff
Compare
Co-authored-by: Dmitry Skorobogaty <[email protected]> Signed-off-by: Maksim Derbasov <[email protected]>
Signed-off-by: Maksim Derbasov <[email protected]>
ccfcb2d
to
0ba046a
Compare
Sorry for a delay. Here is an another solution. We are grouping all points by x coordinate and check only points with a same x coordinate (and adjacent groups, due to For a relatively small sub-meshes it works slower(on my hardware, around 8 milliseconds) than previous one. It looks like a minimal running time constant. Not sure how critical is it. If it's a showstopper, I can dispatch algorithms according to a input size, but it will make code more complex(for a future readers), that's why I came with this version first.
And the last thing, I don't have a full gazebo setup in current environment, can rely only on unit tests (w/o visual manual check) |
Signed-off-by: Maksim Derbasov <[email protected]>
Signed-off-by: Maksim Derbasov <[email protected]>
graphics/src/SubMesh.cc
Outdated
if (this->dataPtr->normals.size() < 3u) | ||
if (this->dataPtr->indices.empty() | ||
|| this->dataPtr->indices.size() % 3u != 0) | ||
return; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It feels like it also should check: || this->dataPtr->primitiveType != SubMesh::TRIANGLES
but not 100% sure that it's only one primitiveType
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1, I think it's good to be explicit and check that it's a TRIANGLES primitive type. I think other primitive types don't quite work yet but this is just in case better support is implemented for other types in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new approach looks fine to me. I tested the code and the capsule renders fine without the seam. Just one minor comment on adding some doc to explain the logic.
graphics/src/SubMesh.cc
Outdated
if (this->dataPtr->normals.size() < 3u) | ||
if (this->dataPtr->indices.empty() | ||
|| this->dataPtr->indices.size() % 3u != 0) | ||
return; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1, I think it's good to be explicit and check that it's a TRIANGLES primitive type. I think other primitive types don't quite work yet but this is just in case better support is implemented for other types in the future.
} | ||
|
||
template<typename Visitor> | ||
void Visit(const gz::math::Vector3d &_point, Visitor _v) const |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add some documentation to explain the logic in this function? I think it's to find and include all indices of vertices that are within the tolerance of the math::equal
checks, so that their normals all count towards the final calculation?
Signed-off-by: Maksim Derbasov <[email protected]>
4feb0b3
to
cd01fa6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good, thanks for iterating
🦟 Bug fix
Fixes #N/A
Summary
Previous version of
RecalculateNormals
member function has a O(n^2) complexity because inner loop where we are looking for normal elements. But we already know indexes of this elements. So we can get rid of inner loop.And seems we should check
indices.size() < 3u || indices.size() % 3u != 0
due to if it will be 4, main loop will start and on second iteration it will start reading out of array.Also seems condition in the begin should check amount of indexes/vector, but not normals, due to we are resizing it later.
Maybe this function also should have a check of
enum PrimitiveType
of data, seems attempt to call it forPOINTS
andLINES
is not legit (for rest 4 types maybe it's ok, not sure)Checklist
codecheck
passed (See contributing)Note to maintainers: Remember to use Squash-Merge and edit the commit message to match the pull request summary while retaining
Signed-off-by
messages.